package com.zhouyibike.uu.ui.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.zhouyibike.uu.R;
import com.zhouyibike.uu.utils.ImgUtils;


import java.io.File;
import java.util.HashMap;

/**
 * Created by cc on 2017/5/23.
 */

public class PicAdapter extends BaseAdapter {
    private Context context;
    private HashMap<Integer,String> allpic=new HashMap<>();
//    private ImageOptions imageOptions;
    public PicAdapter(Context context, HashMap<Integer,String> allpic) {
        this.context = context;
        this.allpic = allpic;
    }
    public void setlist( HashMap<Integer,String> allpic){
        this.allpic = allpic;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if(allpic.size()==3){
            return 3;
        }else
        return allpic.size()+1;
    }

    @Override
    public Object getItem(int position) {

        if(position==allpic.size()){
            return "";
        }else
        return allpic.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView= LayoutInflater.from(context).inflate(R.layout.item_pic,null);
        ImageView iv_pic= (ImageView) convertView.findViewById(R.id.iv_itempic_pic);
        if(position==allpic.size()){

        }else{
            File file=new File(allpic.get(position));
            if (file.exists())
            {
                Bitmap bm= ImgUtils.compressImageFromFile(allpic.get(position));
               // Bitmap bm= ImgUtils.compressImage(allpic.get(position));
              //  Picasso.with(context).load(file).resize(150,150).error(R.drawable.bgbeijingtu).centerCrop().into(iv_pic);
                iv_pic.setImageBitmap(bm);
            }
        }
//        Util.setLviewwh(iv_pic,100,80,0.25);
        return convertView;
    }
}
